<template>
  <div>
    <!-- 面包屑导航区  -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区 -->
    <el-card>
      <!-- 搜索区域 -->
      <el-row :gutter="20">
        <el-col :span="10">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getOrderList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getNewOrderList"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 订单列表数据 -->
      <el-table :data="orderList" border stripe style="width: 100%">
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column label="订单编号" prop="order_number">
        </el-table-column>
        <el-table-column label="订单价格" prop="order_price" width="100px">
        </el-table-column>
        <el-table-column label="付款状态" prop="pay_status" width="100px">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="75px">
        </el-table-column>
        <el-table-column label="下单时间" prop="create_time" width="165px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="140px">
          <template>
            <el-tooltip
              effect="dark"
              content="修改地址"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="editDialogVisible = true"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="dark"
              content="定位"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="success"
                icon="el-icon-location-information"
                size="mini"
                @click="locatDialog"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页功能 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[7, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>

    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="closeDialogVisible"
    >
      <el-form
        :model="editAddressForm"
        :rules="editRules"
        ref="editRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader :options="cityDta" v-model="editAddressForm.address1">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 物流定位对话框 -->
    <el-dialog
      title="定位对话框"
      :visible.sync="locatDialogVisible"
      width="50%"
    >
      <span>由于后台API有问题，这里的数据就没有获取了！</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="locatDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="locatDialogVisible =false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityDta from "./citydata.js";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 7,
      },
      //订单页数
      total: 0,
      //订单列表数据
      orderList: [],
      //控制修改地址和定位对话框的显示与隐藏
      editDialogVisible: false,
      locatDialogVisible:false,
      //修改地址对话框表单数据
      editAddressForm: {
        address1: [],
        address2: "",
      },
      //修改地址对话框表单数据验证规则对象
      editRules: {
        address1: [
          { required: true, message: "请选择省市区/县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请填写详细地址", trigger: "blur" },
        ],
      },
      //城市区域数据
      cityDta,
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200) {
        return this.$message.error("获取订单列表数据失败！");
      }
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },
    //清除查询订单信息
    // clearNewOrderList() {
    //   this.getOrderList();
    // },
    //查询订单信息
    getNewOrderList() {
      this.getOrderList();
      this.$message.success("查询订单成功！");
    },
    //每一页的数据的条数
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    //当前页码值
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getOrderList();
    },
    //关闭表单时重置表单
    closeDialogVisible() {
      this.$refs.editRef.resetFields();
    },
    //物流信息数据获取（这里的后台数据有点问题，就不写了）
    locatDialog(){
        this.locatDialogVisible = true;
    },
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.el-cascader {
  width: 100%;
}
</style>
